package com.jbl.te.controller;

import com.jbl.commonutils.R;
import com.jbl.te.entity.Test;
import com.jbl.te.service.TestService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jbl
 * @since 2020-12-07
 */
@RestController
@RequestMapping("/te/test")
@CrossOrigin
public class TestController {

    @Autowired
    TestService testService;


    @GetMapping("getAllTest")
    @ApiOperation("获取所有test")
    public R getAllTest() {
        List<Test> list = testService.list();
        return R.ok().data("list",list);
    }

    @PostMapping("addTest")
    @ApiOperation("添加test")
    public R addTest(@RequestBody Test test) {
        boolean b = testService.save(test);
        if(b) return R.ok();
        return R.error().message("添加失败");
    }

    @PutMapping("editTest")
    @ApiOperation("修改test")
    public R editTest(@RequestBody Test test) {
        boolean update = testService.updateById(test);
        if(update) return R.ok();
        return R.error().message("修改失败");
    }

    @DeleteMapping("delTestById")
    @ApiOperation("删除test")
    public R delTest(String id) {
        boolean b = testService.removeById(id);
        if(b) return R.ok();
        return R.error().message("删除失败");
    }

}

